package controller.notice;

import base.response.OffsetLimitPage;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import controller.common.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import services.notice.NoticeAccountServices;
import services.notice.NoticeInfoServices;
import services.notice.NoticeRoleServices;
import wt.entity.notice.NoticeInfo;

import java.util.Date;
import java.util.List;

/**
 * 功能:
 * 作者: 洪世成
 * 日期: 2017/9/9
 * 版权所有: admin
 */
@Controller
@RequestMapping("notice/noticeInfoSelect")
public class NoticeInfoSelectController extends BaseController {

    @Autowired
    NoticeInfoServices noticeInfoServices;
    @Autowired
    NoticeRoleServices noticeRoleServices;
    @Autowired
    NoticeAccountServices noticeAccountServices;

    @RequiresPermissions("notice:noticeInfoSelect:default")
    @RequestMapping("index")
    public String index() {
        return "notice/noticeInfoSelect/index";
    }

    @RequiresPermissions("notice:noticeInfoSelect:default")
    @ResponseBody
    @RequestMapping("select")
    public OffsetLimitPage select(@DateTimeFormat(pattern = "yyyy-MM-dd") Date  startTime,
                                  @DateTimeFormat(pattern = "yyyy-MM-dd") Date  endTime,
                                  String noticeType,
                                  Integer limit, Integer offset) throws Exception {

        PageHelper.offsetPage(offset, limit);

        List<NoticeInfo> noticeInfoList = noticeInfoServices.select(noticeType,getLoginAccount().getId(), getLoginAccount().getRole().getId(), startTime, endTime);

        return new OffsetLimitPage((Page) noticeInfoList);

    }

}
